<?php

namespace app\data\service;

use app\data\model\CaseCmsJoinModel;
use app\data\model\CaseModel;
use app\data\model\CaseProductJoinModel;
use app\data\model\CmsModel;
use app\data\model\ProModel;

class JoinService extends BaseService
{
    protected CaseModel $caseModel;
    protected ProModel $proModel;
    protected CmsModel $cmsModel;
    protected CaseProductJoinModel $joinCaseProductModel;
    protected CaseCmsJoinModel $joinCaseCmsModel;

    public function __construct(){
        $this->caseModel = new CaseModel();
        $this->proModel = new ProModel();
        $this->joinCaseProductModel = new CaseProductJoinModel();
        $this->cmsModel = new CmsModel();
        $this->joinCaseCmsModel = new CaseCmsJoinModel();
    }

    public function addCaseProductJoin($data): int
    {
        return $this->joinCaseProductModel->add($data);
    }

    public function addCaseProductJoinData($data): int
    {
        return $this->joinCaseProductModel->addAll($data);
    }

    public function addCaseCmsJoin($data): int
    {
        return $this->joinCaseCmsModel->add($data);
    }

    public function addCaseCmsJoinData($data): int
    {
        return $this->joinCaseCmsModel->addAll($data);
    }

    public function delCaseCmsJoin($where): bool|int
    {
        return $this->joinCaseCmsModel->softDel($where);
    }

    public function delCaseProductJoin($where): bool|int
    {
        return $this->joinCaseProductModel->softDel($where);
    }


    public function getProductIdsByCaseId($case_id): array
    {
        return $this->joinCaseProductModel->findAll(['case_id'=>$case_id],'product_id','');
    }

    public function getProductInfo($ids = []): array
    {
        $where[] = ['id','in',$ids];
        return $this->proModel->findAll($where,'*','');
    }

    public function getCmsIdsByCaseId($case_id): array
    {
        return $this->joinCaseCmsModel->findAll(['case_id'=>$case_id],'cms_id','');
    }

    public function getCmsInfo($ids = []): array
    {
        $where[] = ['article_id','in',$ids];
        return $this->proModel->findAll($where,'*','');
    }
}